﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//Please add references
namespace DataAccess
{
    /// <summary>
    /// 数据访问类:ZL_HSRK_T
    /// </summary>
    public partial class ZL_HSRK_T
    {
        public ZL_HSRK_T()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(decimal ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ZL_HSRK_T");
            strSql.Append(" where ID=:ID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)};
            parameters[0].Value = ID;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static decimal Add(Model.ZL_HSRK_T model)
        {
            model.ID = CommonExecute.GetID("ZL_HSRK_T");
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ZL_HSRK_T(");
            strSql.Append("ID,TS,SQDH,SQMC,SMFBL,HSBLC,YPS,JSRQ,RKRQ,HSDW,SMDW,YQLX,BZ,CREATE_USER,CREATE_DATE)");
            strSql.Append(" values (");
            strSql.Append(":ID,:TS,:SQDH,:SQMC,:SMFBL,:HSBLC,:YPS,:JSRQ,:RKRQ,:HSDW,:SMDW,:YQLX,:BZ,:CREATE_USER,:CREATE_DATE)");
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,10),
					new OracleParameter(":TS", OracleType.Number,1),
					new OracleParameter(":SQDH", OracleType.Number,10),
					new OracleParameter(":SQMC", OracleType.NVarChar),
					new OracleParameter(":SMFBL", OracleType.NVarChar),
					new OracleParameter(":HSBLC", OracleType.NVarChar),
					new OracleParameter(":YPS", OracleType.Number,10),
					new OracleParameter(":JSRQ", OracleType.DateTime),
					new OracleParameter(":RKRQ", OracleType.DateTime),
					new OracleParameter(":HSDW", OracleType.NVarChar),
					new OracleParameter(":SMDW", OracleType.NVarChar),
					new OracleParameter(":YQLX", OracleType.NVarChar),
					new OracleParameter(":BZ", OracleType.NVarChar),
					new OracleParameter(":CREATE_USER", OracleType.NVarChar),
					new OracleParameter(":CREATE_DATE", OracleType.NVarChar)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.TS;
            parameters[2].Value = model.SQDH;
            parameters[3].Value = model.SQMC;
            parameters[4].Value = model.SMFBL;
            parameters[5].Value = model.HSBLC;
            parameters[6].Value = model.YPS;
            parameters[7].Value = model.JSRQ;
            parameters[8].Value = model.RKRQ;
            parameters[9].Value = model.HSDW;
            parameters[10].Value = model.SMDW;
            parameters[11].Value = model.YQLX;
            parameters[12].Value = model.BZ;
            parameters[13].Value = model.CREATE_USER;
            parameters[14].Value = model.CREATE_DATE;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return model.ID;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static bool Update(Model.ZL_HSRK_T model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ZL_HSRK_T set ");
            strSql.Append("TS=:TS,");
            strSql.Append("SQDH=:SQDH,");
            strSql.Append("SQMC=:SQMC,");
            strSql.Append("SMFBL=:SMFBL,");
            strSql.Append("HSBLC=:HSBLC,");
            strSql.Append("YPS=:YPS,");
            strSql.Append("JSRQ=:JSRQ,");
            strSql.Append("RKRQ=:RKRQ,");
            strSql.Append("HSDW=:HSDW,");
            strSql.Append("SMDW=:SMDW,");
            strSql.Append("YQLX=:YQLX,");
            strSql.Append("BZ=:BZ,");
            strSql.Append("CREATE_USER=:CREATE_USER,");
            strSql.Append("CREATE_DATE=:CREATE_DATE");
            strSql.Append(" where ID=:ID ");
            OracleParameter[] parameters = {
					new OracleParameter(":TS", OracleType.Number,1),
					new OracleParameter(":SQDH", OracleType.Number,10),
					new OracleParameter(":SQMC", OracleType.NVarChar),
					new OracleParameter(":SMFBL", OracleType.NVarChar),
					new OracleParameter(":HSBLC", OracleType.NVarChar),
					new OracleParameter(":YPS", OracleType.Number,10),
					new OracleParameter(":JSRQ", OracleType.DateTime),
					new OracleParameter(":RKRQ", OracleType.DateTime),
					new OracleParameter(":HSDW", OracleType.NVarChar),
					new OracleParameter(":SMDW", OracleType.NVarChar),
					new OracleParameter(":YQLX", OracleType.NVarChar),
					new OracleParameter(":BZ", OracleType.NVarChar),
					new OracleParameter(":CREATE_USER", OracleType.NVarChar),
					new OracleParameter(":CREATE_DATE", OracleType.NVarChar),
					new OracleParameter(":ID", OracleType.Number,10)};
            parameters[0].Value = model.TS;
            parameters[1].Value = model.SQDH;
            parameters[2].Value = model.SQMC;
            parameters[3].Value = model.SMFBL;
            parameters[4].Value = model.HSBLC;
            parameters[5].Value = model.YPS;
            parameters[6].Value = model.JSRQ;
            parameters[7].Value = model.RKRQ;
            parameters[8].Value = model.HSDW;
            parameters[9].Value = model.SMDW;
            parameters[10].Value = model.YQLX;
            parameters[11].Value = model.BZ;
            parameters[12].Value = model.CREATE_USER;
            parameters[13].Value = model.CREATE_DATE;
            parameters[14].Value = model.ID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static bool Delete(decimal ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ZL_HSRK_T ");
            strSql.Append(" where ID=:ID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)};
            parameters[0].Value = ID;

            int rows = DbHelperOra.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public static bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ZL_HSRK_T ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = DbHelperOra.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Model.ZL_HSRK_T GetModel(decimal ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,TS,SQDH,SQMC,SMFBL,HSBLC,YPS,JSRQ,RKRQ,HSDW,SMDW,YQLX,BZ,CREATE_USER,CREATE_DATE from ZL_HSRK_T ");
            strSql.Append(" where ID=:ID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)};
            parameters[0].Value = ID;

            Model.ZL_HSRK_T model = new Model.ZL_HSRK_T();
            DataSet ds = DbHelperOra.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = decimal.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["TS"] != null && ds.Tables[0].Rows[0]["TS"].ToString() != "")
                {
                    model.TS = decimal.Parse(ds.Tables[0].Rows[0]["TS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SQDH"] != null && ds.Tables[0].Rows[0]["SQDH"].ToString() != "")
                {
                    model.SQDH = decimal.Parse(ds.Tables[0].Rows[0]["SQDH"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SQMC"] != null && ds.Tables[0].Rows[0]["SQMC"].ToString() != "")
                {
                    model.SQMC = ds.Tables[0].Rows[0]["SQMC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SMFBL"] != null && ds.Tables[0].Rows[0]["SMFBL"].ToString() != "")
                {
                    model.SMFBL = ds.Tables[0].Rows[0]["SMFBL"].ToString();
                }
                if (ds.Tables[0].Rows[0]["HSBLC"] != null && ds.Tables[0].Rows[0]["HSBLC"].ToString() != "")
                {
                    model.HSBLC = ds.Tables[0].Rows[0]["HSBLC"].ToString();
                }
                if (ds.Tables[0].Rows[0]["YPS"] != null && ds.Tables[0].Rows[0]["YPS"].ToString() != "")
                {
                    model.YPS = decimal.Parse(ds.Tables[0].Rows[0]["YPS"].ToString());
                }
                if (ds.Tables[0].Rows[0]["JSRQ"] != null && ds.Tables[0].Rows[0]["JSRQ"].ToString() != "")
                {
                    model.JSRQ = DateTime.Parse(ds.Tables[0].Rows[0]["JSRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RKRQ"] != null && ds.Tables[0].Rows[0]["RKRQ"].ToString() != "")
                {
                    model.RKRQ = DateTime.Parse(ds.Tables[0].Rows[0]["RKRQ"].ToString());
                }
                if (ds.Tables[0].Rows[0]["HSDW"] != null && ds.Tables[0].Rows[0]["HSDW"].ToString() != "")
                {
                    model.HSDW = ds.Tables[0].Rows[0]["HSDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SMDW"] != null && ds.Tables[0].Rows[0]["SMDW"].ToString() != "")
                {
                    model.SMDW = ds.Tables[0].Rows[0]["SMDW"].ToString();
                }
                if (ds.Tables[0].Rows[0]["YQLX"] != null && ds.Tables[0].Rows[0]["YQLX"].ToString() != "")
                {
                    model.YQLX = ds.Tables[0].Rows[0]["YQLX"].ToString();
                }
                if (ds.Tables[0].Rows[0]["BZ"] != null && ds.Tables[0].Rows[0]["BZ"].ToString() != "")
                {
                    model.BZ = ds.Tables[0].Rows[0]["BZ"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_USER"] != null && ds.Tables[0].Rows[0]["CREATE_USER"].ToString() != "")
                {
                    model.CREATE_USER = ds.Tables[0].Rows[0]["CREATE_USER"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_DATE"] != null && ds.Tables[0].Rows[0]["CREATE_DATE"].ToString() != "")
                {
                    model.CREATE_DATE = ds.Tables[0].Rows[0]["CREATE_DATE"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,TS,SQDH,SQMC,SMFBL,HSBLC,YPS,JSRQ,RKRQ,HSDW,SMDW,YQLX,BZ,CREATE_USER,CREATE_DATE ");
            strSql.Append(" FROM ZL_HSRK_T ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "ZL_HSRK_T";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

